package com.ruoyi.web.controller.app.controller;

import com.ruoyi.framework.web.exception.base.XResult;
import com.ruoyi.web.controller.app.service.AppShippingAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

/**
 * @ClassName ShippingAddressController
 * @Description 收货地址
 * @Author tyc@yanyu
 * @Date 2018/12/10 0010 11:40
 **/
@RestController
@RequestMapping("/app/shipAdress")
@Api(tags = "收货地址")
public class AppShippingAddressController {

    @Autowired
    private AppShippingAddressService shippingAddressService;

    @RequestMapping(value = "addAddress",method = RequestMethod.POST)
    @ApiOperation(value = "新增收货地址",position = 1,notes = "新增收货地址")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "memberId", value = "用户ID号", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "realname", value = "真实姓名", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "mobile", value = "电话", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "address", value = "具体地址", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "province", value = "省", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "city", value = "市", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "area", value = "区", required = false, dataType = "String", paramType = "query"),
    })
    public XResult addAddress(@RequestParam @ApiIgnore Map<String,String> map){
        return new XResult("操作成功",shippingAddressService.addAddress(map));
    }

    /**
     * 收货地址列表
     * @param memberId
     * @return
     */

    @RequestMapping(value = "getAddress",method = RequestMethod.POST)
    @ApiOperation(value = "收货地址列表",position = 2,notes = "收货地址列表")
    @ApiImplicitParam(name = "memberId", value = "用户ID号", required = true, dataType = "String", paramType = "query")
    public XResult getAddress(String memberId){
        return new XResult("操作成功",shippingAddressService.queryAddress(memberId));
    }

    /**
     * 编辑收货地址
     * @param map
     * @return
     */
    @RequestMapping(value = "updateAddress",method = RequestMethod.POST)
    @ApiOperation(value = "编辑收货地址",position = 3,notes = "编辑收货地址")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "地址id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "realname", value = "真实姓名", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "mobile", value = "电话", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "address", value = "具体地址", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "province", value = "省", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "city", value = "市", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "area", value = "区", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "isdefault", value = "是否默认 1、是 2、否", required = false, dataType = "String", paramType = "query")
    })
    public XResult updateAddress(@RequestParam @ApiIgnore Map<String,String> map){
        return new XResult("操作成功",shippingAddressService.updateAddress(map));
    }

    /**
     * 删除收货地址
     * @param id
     * @return
     */
    @RequestMapping(value = "deleteAddress",method = RequestMethod.POST)
    @ApiOperation(value = "删除收货地址",position = 4,notes = "删除收货地址")
    @ApiImplicitParam(name = "id", value = "信息id", required = true, dataType = "String", paramType = "query")
    public XResult deleteAddress(String id){
        return new XResult("操作成功",shippingAddressService.deleteAddress(id));
    }

    /**
     * 是否默认
     * @param id
     * @return
     */
    @RequestMapping(value = "updateStatus",method = RequestMethod.POST)
    @ApiOperation(value = "更改状态（是否默认1、是 2、否）",position = 5,notes = "更改状态")
    @ApiImplicitParam(name = "id", value = "信息id", required = true, dataType = "String", paramType = "query")
    public XResult updateStatus(String id,String memberId){
        return new XResult("操作成功",shippingAddressService.updateStatus(id,memberId));
    }

}
